package com.self.concurrent;

public class SyncTest {


    public void method1() {
        synchronized (this) {
            try {
                System.out.println("method1 wait");
                SyncTest.class.wait();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("method1");

        }
    }

    public void method2() {
        synchronized (this) {
            System.out.println("method2");
        }
    }

    public static void main(String[] args) throws InterruptedException {
        final SyncTest tt = new SyncTest();
        new Thread(new Runnable() {
            @Override
            public void run() {
                synchronized (SyncTest.class) {
                    try {
                        System.out.println("thread in");
                        Thread.sleep(2000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    SyncTest.class.notify();
                    System.out.println("thread notify");
                }
            }
        }).start();

        synchronized (SyncTest.class) {
            System.out.println("main wait");
            Thread.sleep(2000);
            SyncTest.class.wait();
            System.out.println("main begin");
        }
    }
}
